package com.kiln.juxingqs.ui

import android.content.Intent
import android.view.View
import android.widget.AdapterView
import androidx.lifecycle.Observer
import client.global.commlib.dialog.CameraOrSelectDialog
import client.global.commlib.toast.toast
import com.kiln.juxingqs.R
import com.kiln.juxingqs.ui.vm.RegisterViewModel
import java.util.*
import com.kiln.juxingqs.BaseMiddleActivity
import com.kiln.juxingqs.databinding.ActivityRealabledateVerifyBinding
import com.kiln.juxingqs.dialog.SelectDateRangeDialog
import com.kiln.juxingqs.ui.vm.RealAbleDateViewModel

class RealAbleDateVerifyActivity :
    BaseMiddleActivity<RealAbleDateViewModel, ActivityRealabledateVerifyBinding>() {
    override fun getLayout(): Int {
        return R.layout.activity_realabledate_verify
    }

    override fun initViewModel(): RealAbleDateViewModel = createViewModel()


    override fun initView() {
        binding?.apply {
            login = this@RealAbleDateVerifyActivity
            vm = viewModel
        }
    }

    override fun observerUI() {
        viewModel.call.observe(this, Observer {
            it?.apply {
                if (isSuccess) {
                    toast("已提交")//
                    if (intent.getBooleanExtra("isLogin", false)) {
                        startActivity(Intent(this@RealAbleDateVerifyActivity, MainActivity::class.java))
                    }
                    finish()
                } else {
                    toast(it.message)
                }
            }
        })

    }

    fun goTop() {
        SelectDateRangeDialog(this).apply {
            startDate = viewModel.startDate.value
            endDate = viewModel.endDate.value

            isLongDate.set(viewModel.standard.value.equals("长期"))
            selectCli = { s, e ->
                viewModel.startDate.value = s
                viewModel.endDate.value = e
            }
        }.show()
    }
}